package com.hzhk.happyrent.ui.adapter.rent;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzhk.happyrent.App;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.rent.TypesModel;
import com.hzhk.happyrent.network.HttpManager;
import com.hzhk.happyrent.utils.glide.ShowImageUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HomeFunctionAdapter extends BaseAdapter {

    private TypesModel typesModel;
    private Context context;

    public HomeFunctionAdapter(Context context) {
        super();
        this.context = context;
    }

    public void setList(TypesModel data) {
        if (data != null) {
            typesModel = data;
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return typesModel!= null ?
                typesModel.getData().getGoodsTypes().size() : 0;
    }

    @Override
    public Object getItem(int arg0) {
        return typesModel.getData().getGoodsTypes().get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_home_gridview, null);
        }
        new ViewHolder(convertView).initData(typesModel.getData().getGoodsTypes().get(position).getSortCoverImage(),
                typesModel.getData().getGoodsTypes().get(position).getSortTit());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.item_home_grid_image)
        ImageView itemHomeGridImage;
        @BindView(R.id.item_home_grid_text)
        TextView itemHomeGridText;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        public void initData(String url,String type){
            ShowImageUtils.showImageView(App.getContext(),itemHomeGridImage,url);
            itemHomeGridText.setText(type);
        }
    }
}
